package com.kitty.game.fight.artifact.passive;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.game.fight.bean.SuperBossFightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.service.FightMessageService;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.artifact.ArtifactService;

import java.util.ArrayList;
import java.util.Collections;
//阴阳镜
public class MirrorArtifactEffect extends ArtifactEffect {

    public ArtifactType getType() {
        return ArtifactType.MIRROR;
    }

    @Override
    public short getEffectId() {
        return 8014;
    }

    @Override
    public FightObject trigger(Fight fight, FightObject member, Object... params) {
        /**超级boss另外判断*/
        if (member.isSuperBoss()) {
            return tirggerSuperBoss(fight, member, params);
        }
        if (!checkBaseCondition(fight, member)) {
            return null;
        }
        ArtifactService artifactService = SpringUtils.getBean(ArtifactService.class);
        boolean effect = artifactService.getArtifactRate(getType().getName(), member.getRole());
        if (!effect) {
            return null;
        }

        ArrayList<FightObject> allFightObjs = fight.getAllFightObjects();
        // 随机打乱
        Collections.shuffle(allFightObjs);
        for (FightObject obj : allFightObjs) {
            if (obj.getId() == member.getId() || obj.isFallDown()) {
                continue;
            }
            return obj;
        }
        return null;
    }

    /**
     * 超级boss是否触发法宝
     */
    protected FightObject tirggerSuperBoss(Fight fight, FightObject member, Object... params) {
        if (!checkSuperBossBaseCondition(fight, member)) {
            return null;
        }
        boolean trigger = SpringUtils.getArtifactService().getSuperBossArtifactRate(getType().getName(), (SuperBossFightObject) member);
        if (!trigger) {
            return null;
        }

        ArrayList<FightObject> allFightObjs = fight.getAllFightObjects();
        // 随机打乱
        Collections.shuffle(allFightObjs);
        for (FightObject obj : allFightObjs) {
            if (obj.getId() == member.getId() || obj.isFallDown()) {
                continue;
            }
            return obj;
        }
        return null;
    }

    /**
     * 特效广播
     *
     * @param fight
     * @param member
     * @param params
     */
    @Override
    public void broadCast(Fight fight, FightObject member, Object... params) {
        FightObject target = (FightObject) params[0];
        FightMessageService fightMessageService = SpringUtils.getBean(FightMessageService.class);
        FightMessageUtil.sendFightPackage(fight, fightMessageService.createSequence(target.getId()));
        FightMessageUtil.sendFightPackage(fight, fightMessageService.attackSkillEffect(member.getId(), getEffectId(), "", 0));
        FightMessageUtil.sendFightPackage(fight, fightMessageService.attackSkillEffect(target.getId(), (short) 1077, "", 0));
    }

}
